package com.yangsir.mysite.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yangsir.mysite.common.R;
import com.yangsir.mysite.pojo.Tag;
import com.yangsir.mysite.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * java 8
 */
@CrossOrigin
@RestController
@RequestMapping("/tags")
public class TagsController {
    @Autowired
    private TagService tagService;
    @GetMapping("/getTags")
    public R<List<Tag>> getTags(Integer type) {
        if (type == null) {
            return R.error("关键参数为空");
        }
        return tagService.quaryAllTags(type);
    }
    @GetMapping("/getAllTags")
    public R<List<Tag>> getAllTags() {
        QueryWrapper<Tag> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("DISTINCT tag_name");
        return R.success(tagService.list(queryWrapper), "标签请求成功");
    }
}
